package com.jie.exception;
import com.jie.vo.CommonResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {
    /*
    全局异常处理，没有指定异常的类型，不管什么异常均可以捕获
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public CommonResponse error(Exception e){
        e.printStackTrace();
        return CommonResponse.buildError(e.getMessage());
    }
    /**
     * 自定义异常触发
    @Description:
    @Param: [e]
    @return: com.jie.vo.CommonResponse
    @Author: xiaojie
    @Date: 2023/11/1
    */
    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public CommonResponse error(BusinessException e){
        e.printStackTrace();
        return CommonResponse.buildCodeAndMsg(e.getCode(),e.getErrorMsg());
    }
  }
